home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / DSMODS / SCANRECT.S < prev    next >
Encoding:
Text File  |  2001-02-10  |  3.6 KB  |  184 lines

  1.  
  2.     globl    _scanner
  3.  
  4.  
  5. *  scan_region(fdb, sx, sy, sh, &rxmin, &rymin, &rxmax)
  6. *
  7. *  iN:    long    fdb        pointer to Form Definition Block
  8. *    int    sx,sy        position to start search
  9. *    int    sh        height of rectangle being searched for
  10. *
  11. * oUT:        d0.w        0:    no more rectangles
  12. *                else: rectangle data good
  13. *    int    rxmin, rymin    position of rectangle upper left corner
  14. *        rxmax        position of rectangle right side
  15. *
  16. *
  17. *    Form Definition Block
  18. *
  19. *    long    BASE        base address of memory form
  20. *    int    FORM_WD        width of form in bytes
  21. *    int    FORM_HT        height of form in pixels
  22. *    int    B_XMIN        Xmin of bounding rectangle
  23. *    int    B_YMIN        Ymin of bounding rectangle
  24. *    int    B_XMAX        Xmax of bounding rectangle
  25. *    int    B_YMAX        Xmax of bounding rectangle
  26.  
  27. WS    equ    20
  28.  
  29. FDB    equ    WS+04
  30. SX    equ    WS+08
  31. SY    equ    WS+10
  32. SH    equ    WS+12
  33. RXMIN    equ    WS+14
  34. RYMIN    equ    WS+18
  35. RXMAX    equ    WS+22
  36.  
  37. BASE    equ    00
  38. FORM_WD    equ    04
  39. FORM_HT    equ    06
  40. B_XMIN    equ    08
  41. B_YMIN    equ    10
  42. B_XMAX    equ    12
  43. B_YMAX    equ    14
  44.  
  45.  
  46. _scanner:
  47.  
  48.     movem.l    d3-d7,-(sp)
  49.  
  50.     move.l    FDB(sp),a2    ; a2 -> form definition block
  51.     move.w    B_XMIN(a2),d0    ; d0 <- minimum X search position
  52.     move.w    SX(sp),d3    ; d3 <- current X search position
  53.     cmp.w    d0,d3        ; clip if neccessary
  54.     bcc    .1
  55.  
  56.     move.w    d0,d3
  57.  
  58. .1:    move.w    SY(sp),d5    ; d5 <- current Y search position
  59.     move.w    SH(sp),d6
  60.     subq.w    #1,d6        ; d6 <- dbra height count
  61.  
  62.     move.w    FORM_WD(a2),d1    ; d1 <- offset to next line
  63.     move.w    d5,d0
  64.     mulu    d1,d0        ; d0 <- offset to (0,SY)
  65.  
  66.     move.l    BASE(a2),a0    ; a0 -> base of memory form
  67.     add.l    d0,a0        ; a0 -> (0,SY)
  68.     move.w    d3,d0        ; d0 <- SX
  69.     lsr.w    #4,d0
  70.     add.w    d0,d0        ; d0 <- offset to word containing (SX,0)
  71.     add.w    d0,a0        ; a0 -> beginning of search (sx,sy)
  72.  
  73.     move.w    d3,d2
  74.     not.w    d2
  75.     and.w    #15,d2        ; d2 -> bit within word where search begins
  76.  
  77.     move.w    B_XMAX(a2),d4    ; d4 <- maximum X of bounding rectangle
  78.     cmp.w    d4,d3        ; if SX is beyond right border,
  79.     bhi    .eol        ; go to next line
  80.  
  81.  
  82. *    find inscribed rectangle Xmin
  83.  
  84. .100:    move.l    a0,a1
  85.     move.w    (a0)+,d0        ; d0 <- data from 1st row
  86.     move.w    d6,d7            ; d7 <- height counter
  87.  
  88. .200:    and.w    (a1),d0            ; d0 <- compressed column
  89.     add.w    d1,a1
  90.     dbra    d7,.200
  91.  
  92. .300:    btst.l    d2,d0
  93.     bne    .xmin
  94.  
  95.     cmp.w    d4,d3
  96.     bcc    .eol
  97.  
  98.     addq.w    #1,d3
  99.     dbra    d2,.300
  100.  
  101.     moveq.l    #15,d2
  102.     bra    .100    
  103.  
  104.  
  105. .eol:    add.w    SH(sp),d5        ; d5 <- newY := oldY + search height
  106.     move.w    B_YMAX(a2),d7        ; d7 <- bounding rectangle Ymax
  107.     sub.w    d6,d7            ; d7 <- maximum newY
  108.     cmp.w    d7,d5            ; if new Y is greater than maximum ...
  109.     bls    .cont            ; search terminates
  110.  
  111.     clr.w    d0            ; no more rectangles
  112.     bra    .end            ; clean up and leave
  113.  
  114. .cont:    move.w    d5,d7
  115.     mulu    d1,d7            ; d7 <- offset to (0,newY)
  116.     move.l    BASE(a2),a0
  117.     add.l    d7,a0            ; a0 -> (0,newY)
  118.  
  119.     move.w    B_XMIN(a2),d3        ; d3 <- initial search X
  120.  
  121.     move.w    d3,d2
  122.     not.w    d2
  123.     and.w    #15,d2            ; d2 -> initial intra-word bit
  124.  
  125.     move.w    d3,d7
  126.     lsr.w    #4,d7
  127.     add.w    d7,d7
  128.     add.w    d7,a0            ; a0 -> (B_XMIN, Ynew)
  129.  
  130.     move.w    B_XMAX(a2),d4        ; d4 <- Xmax for bounding region
  131.     bra    .100
  132.  
  133.  
  134. .xmin:    move.l    RXMIN(sp),a1
  135.     move.w    d3,(a1)            ; save RX
  136.     move.l    RYMIN(sp),a1
  137.     move.w    d5,(a1)            ; save RY
  138.  
  139.  
  140. *    is Xmax in same word as Xmin ?
  141.  
  142.  
  143. .400:    btst.l    d2,d0
  144.     beq    .xmax
  145.  
  146.     cmp.w    d4,d3
  147.     bcc    .xmax
  148.  
  149.     addq.w    #1,d3
  150.     dbra    d2,.400    
  151.  
  152.  
  153. *    search for Xmax in folowing words
  154.  
  155. .500:    move.l    a0,a1
  156.     move.w    (a0)+,d0        ; d0 <- data from 1st row
  157.     moveq.l    #15,d2            ; d2 -> hi bit in word
  158.     move.w    d6,d7            ; d7 <- height counter
  159.  
  160. .600:    and.w    (a1),d0            ; d0 <- compressed column
  161.     add.w    d1,a1
  162.     dbra    d7,.600
  163.  
  164. .700:    btst.l    d2,d0
  165.     beq    .xmax
  166.  
  167.     addq.w    #1,d3
  168.     cmp.w    d4,d3
  169.     bhi    .xmax
  170.  
  171.     dbra    d2,.700
  172.     bra    .500    
  173.  
  174.  
  175. .xmax:    move.l    RXMAX(sp),a1
  176.     subq.w    #1,d3
  177.     move.w    d3,(a1)
  178.     st    d0            ; data is good
  179.  
  180. .end:    movem.l    (sp)+,d3-d7
  181.     rts
  182.  
  183. ə
  184.